package day02.test;

public class test1 {
 public static void main(String[] args) {
	 int b[]= {9,2,3,8,5,6,7};
	// bubbleSort(b);
	// selectionSort(b);
	 int c[]= {1,2,4,5,6,7,9};
	System.out.println(quickSelect(c,9));
}
 public static void bubbleSort(int a[]) {
	 for(int c:a){
		 System.out.print(c+" ");
		 }
	 for(int i=0;i<a.length-1;i++) {
		 for(int j=0;j<a.length-1-i;j++) {
			 if(a[j]>a[j+1]) {
				 int temp;
				 temp=a[j];
				 a[j]=a[j+1];
				 a[j+1]=temp;
				 
				 
			 }
			 
		 }
		 
		 
	 }
	 System.out.println();
	 for(int b:a){
		 System.out.print(b+" ");
		 
		 
	 }
 }
 public static void selectionSort(int a[]) {
	 int temp;
	 int point;
	 for(int i=0;i<a.length-1;i++) {
		 point=i;
		 for(int j=i+1;j<a.length;j++) {
			if(a[point]>a[j]) {
				point=j;
				
			}
			 
			 
			 
		 }
		

		 temp=a[i];
		 a[i]=a[point];
		 a[point]=temp;
		 
	 }
	 for(int b:a){
		 System.out.print(b+" ");
		 
		 
	 }
	 
 }
 public static int quickSelect(int a[],int key) {
	 int high =a.length-1;
     int low=0;
     
  while(low<=high) {
	  int mid=(high+low)/2;
	  if(key==a[mid]) {
		  
		  return mid;
		 
	  }else if(key<a[mid]) {
		  high=mid-1;
	  }else {
		  
		  low=mid+1;
	  }
	  
  }
  System.out.println("找不到");
  return -1;
 }
 
 }
 
